﻿using System;
using Assist;
using Autodesk.Revit.Attributes;
using Autodesk.Revit.DB;
using Autodesk.Revit.UI;
using HYView;

namespace Model
{
	[Transaction(TransactionMode.Manual)]
	[Regeneration(RegenerationOption.Manual)]
	public class CmdDrawRiserBridge : IExternalCommand
	{
		public Result Execute(ExternalCommandData commandData, ref string message, ElementSet elements)
		{
			Document document = commandData.Application.ActiveUIDocument.Document;
			Autodesk.Revit.DB.View activeView = document.ActiveView;
			if ((int)activeView.ViewType != 1 && (int)activeView.ViewType != 2)
			{
				Result result = SwitchView.SetUsableView((CmdViewType)3, commandData);
				if (result != Result.Succeeded)
				{
					return result;
				}
			}
			if (activeView is ViewPlan && activeView.SketchPlane == null)
			{
				Plane plane = RevitVersionFuncs.CreatePlanByOriginAndBasis(activeView.Origin, activeView.RightDirection, activeView.UpDirection);
				Transaction transaction = new Transaction(document, "SketchPlane");
				transaction.Start();
				SketchPlane sketchPlane = RevitVersionFuncs.NewSketchPlane(document, plane);
				activeView.SketchPlane = sketchPlane;
				transaction.Commit();
			}
			new DrawRiserBridge(commandData).Excute();
			return Autodesk.Revit.UI.Result.Succeeded;
		}
	}
}
